package com.scaffold.commons;

import java.util.Properties;

import org.hibernate.MappingException;
import org.hibernate.dialect.Dialect;
import org.hibernate.id.SequenceGenerator;
import org.hibernate.type.Type;

/**
 * 根据表设置sequence名称
 * 可以才entity的超类中设置，特殊情况用@AttributeOverrides注解覆盖。
 * @author wangjg
 *
 */
public class MySequenceGenerator extends SequenceGenerator {
	
	public void configure(Type type, Properties params, Dialect dialect) throws MappingException {
		String table = params.getProperty("target_table");
		String  sequence ="SEQ_"+table.toUpperCase();
		params.setProperty("sequence", sequence);
		
		super.configure(type, params, dialect);
	}
	
}
